using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Sedna.Core.Security
{
    public class HashedCredentialsService : ICredentialsService
    {

        private HashAlgorithm algorithm = new SHA1CryptoServiceProvider();
        
        public bool CheckCredentials(object expected, object actual)
        {
            if (actual == null||String.Empty.Equals(actual)) 
            {
                return false; 
            }
            return expected.Equals(SecureCredentials(actual));
        }

        public object SecureCredentials(object openFormCredentials)
        {
            return Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(openFormCredentials.ToString())));       
        }
    }
}
